package com.orange.score.model.match;

import android.util.Log;
import com.orange.score.android.service.FollowMatchService;
import com.orange.score.constants.ScoreType;
import com.orange.score.model.league.League;
import com.orange.score.model.league.LeagueManager;
import com.orange.score.service.LiveUpdateChangeCallBack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class MatchManager
  implements LiveUpdateChangeCallBack
{
  static final String TAG = "MatchManager";
  Set<String> filterLeagueSet;
  FilterMatchStatusType filterMatchStatus;
  ScoreType filterScoreType;
  List<Match> matchList = new ArrayList();
  Map<String, Match> matchMap = new HashMap();

  public MatchManager()
  {
    this.filterLeagueSet = new HashSet();
    this.filterScoreType = ScoreType.FIRST;
    this.filterMatchStatus = FilterMatchStatusType.ALL;
  }

  public void clearAllLeagues()
  {
    this.filterLeagueSet.clear();
  }

  public List<Match> filterMatch()
  {
    Iterator localIterator;
    ArrayList localArrayList1 = new ArrayList();
    switch ($SWITCH_TABLE$com$orange$score$model$match$FilterMatchStatusType()[this.filterMatchStatus.ordinal()])
    {
    default:
      localIterator = this.matchList.iterator();
    case 5:
    }
    while (true)
    {
      Match localMatch;
      do
      {
        if (!(localIterator.hasNext()))
        {
          ArrayList localArrayList2 = localArrayList1;
          while (true)
          {
            return localArrayList2;
            localArrayList2 = FollowMatchService.getFollowMatchManager().getFollowMatchList();
          }
        }
        localMatch = (Match)localIterator.next();
        if ((this.filterMatchStatus != FilterMatchStatusType.ALL) && (localMatch.getMatchStatusForFilter() != this.filterMatchStatus))
          break label144;
      }
      while (!(this.filterLeagueSet.contains(localMatch.leagueId)));
      localMatch.setIsFollow(FollowMatchService.getFollowMatchManager().isMatchFollowed(localMatch.matchId));
      localArrayList1.add(localMatch);
      label144: Collections.sort(localArrayList1);
    }
  }

  public Match findMatchById(String paramString)
  {
    return ((Match)this.matchMap.get(paramString));
  }

  public Set<String> getFilterLeagueSet()
  {
    return this.filterLeagueSet;
  }

  public FilterMatchStatusType getFilterMatchStatus()
  {
    return this.filterMatchStatus;
  }

  public ScoreType getFilterScoreType()
  {
    return this.filterScoreType;
  }

  public List<Match> getFinishedMatch()
  {
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = this.matchList.iterator();
    while (true)
    {
      Match localMatch;
      do
      {
        if (!(localIterator.hasNext()))
          return localArrayList;
        localMatch = (Match)localIterator.next();
      }
      while (localMatch.getStatus() != -1);
      localArrayList.add(localMatch);
    }
  }

  public List<Match> getMatchList()
  {
    return this.matchList;
  }

  public List<Match> getUnfinishedMatch()
  {
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = this.matchList.iterator();
    while (true)
    {
      Match localMatch;
      do
      {
        if (!(localIterator.hasNext()))
          return localArrayList;
        localMatch = (Match)localIterator.next();
      }
      while (localMatch.getStatus() == -1);
      localArrayList.add(localMatch);
    }
  }

  public void notifyScoreLiveUpdate(List<String[]> paramList)
  {
    int i = paramList.size();
    int j = 0;
    if (j >= i)
      return;
    String[] arrayOfString = (String[])paramList.get(j);
    if ((arrayOfString == null) || (arrayOfString.length < 12));
    while (true)
    {
      while (true)
      {
        while (true)
          ++j;
        Match localMatch = findMatchById(arrayOfString[0]);
        if (localMatch == null)
          break;
        Log.d("MatchManager", "notifyScoreLiveUpdate, match " + localMatch.toString() + " has live change");
        localMatch.updateDataByLiveChange(arrayOfString);
      }
      Log.d("MatchManager", "notifyScoreLiveUpdate, match has live change but not found");
    }
  }

  public void selectAllLeagues(List<League> paramList)
  {
    this.filterLeagueSet.clear();
    Iterator localIterator = paramList.iterator();
    while (true)
    {
      if (!(localIterator.hasNext()))
        return;
      League localLeague = (League)localIterator.next();
      this.filterLeagueSet.add(localLeague.leagueId);
    }
  }

  public void selectLeagues(ArrayList<String> paramArrayList)
  {
    this.filterLeagueSet.clear();
    if (paramArrayList != null)
      this.filterLeagueSet.addAll(paramArrayList);
  }

  public void setFilterLeagueSet(Set<String> paramSet)
  {
    this.filterLeagueSet = paramSet;
  }

  public void setFilterMatchStatus(FilterMatchStatusType paramFilterMatchStatusType)
  {
    this.filterMatchStatus = paramFilterMatchStatusType;
  }

  public void setFilterScoreType(ScoreType paramScoreType)
  {
    if (this.filterScoreType != paramScoreType)
      clearAllLeagues();
    this.filterScoreType = paramScoreType;
  }

  public void setMatchList(List<Match> paramList)
  {
    this.matchList = paramList;
  }

  public void updateDataFromStringList(String[] paramArrayOfString, LeagueManager paramLeagueManager, FollowMatchManager paramFollowMatchManager)
  {
    int i;
    int j;
    this.matchList.clear();
    this.matchMap.clear();
    if ((paramArrayOfString == null) || (paramArrayOfString.length == 0));
    do
    {
      return;
      i = 0;
      j = paramArrayOfString.length;
    }
    while (i >= j);
    String[] arrayOfString = paramArrayOfString[i].split("\\^");
    if (arrayOfString.length < 15)
      Log.w("MatchManager", "updateDataFromStringList but field count not enough, count = " + arrayOfString.length);
    while (true)
    {
      Match localMatch;
      League localLeague;
      do
      {
        while (true)
          ++i;
        localMatch = new Match();
        String str1 = arrayOfString[0];
        String str2 = arrayOfString[1];
        int k = Integer.parseInt(arrayOfString[2]);
        String str3 = arrayOfString[3];
        String str4 = arrayOfString[4];
        String str5 = arrayOfString[5];
        String str6 = arrayOfString[6];
        String str7 = arrayOfString[7];
        String str8 = arrayOfString[8];
        String str9 = arrayOfString[9];
        String str10 = arrayOfString[10];
        String str11 = arrayOfString[11];
        String str12 = arrayOfString[12];
        String str13 = arrayOfString[13];
        String str14 = arrayOfString[14];
        localMatch.setMatchId(str1);
        localMatch.setLeagueId(str2);
        localMatch.setStatus(k);
        localMatch.setDate(str3);
        localMatch.setStartDate(str4);
        localMatch.setHomeTeamName(str5);
        localMatch.setAwayTeamName(str6);
        localMatch.setHomeTeamScore(str7);
        localMatch.setAwayTeamScore(str8);
        localMatch.setHomeTeamFirstHalfScore(str9);
        localMatch.setAwayTeamFirstHalfScore(str10);
        localMatch.setHomeTeamRed(str11);
        localMatch.setAwayTeamRed(str12);
        localMatch.setHomeTeamYellow(str13);
        localMatch.setAwayTeamYellow(str14);
        if (arrayOfString.length >= 16)
          localMatch.setCrownChupan(arrayOfString[15]);
        this.matchList.add(localMatch);
        this.matchMap.put(str1, localMatch);
        localLeague = paramLeagueManager.findLeagueById(str2);
      }
      while (localLeague == null);
      localMatch.setLeagueName(localLeague.name);
      localLeague.increaseMatchCount();
    }
  }

  public void updateMatchDetail(String paramString, String[] paramArrayOfString)
  {
    if ((paramString == null) || (paramString.length() == 0))
      Log.e("MatchManager", "update match detail but matchId is empty");
    while (true)
    {
      Match localMatch;
      while (true)
      {
        return;
        localMatch = findMatchById(paramString);
        if (localMatch != null)
          break;
        Log.d("MatchManager", "updateMatchDetail but matchId " + paramString + " not found");
      }
      localMatch.updateMatchDetail(paramArrayOfString);
    }
  }
}